package thread.pool;

import java.util.concurrent.*;

/**
 * @program: Multhread
 * @description: 线程池参数思考
 * @author: zhanghz001
 * @create: 2021-03-05 15:31
 **/
public class ExecutorTest2 {
    public static void main(String[] args) {
        
        aaa();
        ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(2);
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                3,
                5,
                20,
                TimeUnit.MILLISECONDS,
                queue,
                new RejectedExecutionHandler() {
                    @Override
                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                        System.out.println("reject");
                    }
                }
        );
        
        for (; ; ) {
            poolExecutor.execute(() -> {
                try {
                    Thread.sleep(10000);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    
                }
            });
        }
        
    }
    
    private static void aaa() {
        //
        Executors.newFixedThreadPool(5);
        Executors.newSingleThreadExecutor();
        Executors.newScheduledThreadPool(2);
        Executors.newSingleThreadScheduledExecutor();
        Executors.newWorkStealingPool();
        // ThreadPoolExecutor.AbortPolicy;
        // ThreadPoolExecutor.DiscardPolicy;
        // ThreadPoolExecutor.DiscardOldestPolicy;
        // ThreadPoolExecutor.CallerRunsPolicy;
        // new ReentrantLock().tryLock(100, TimeUnit.MILLISECONDS);
        // this.wait(1111);
    }
}
